Skip to content

Conversation

@weswigham
Copy link
Member

@weswigham weswigham commented Jun 20, 2018

First, in program, as @sheetalkamat suggested, we use the local caches if they have a result for the desired path. Since they still may not (ie, because the file isn't in the program, which is possibly the case when attempting to check paths for module specifiers), we also keep around a "thin" version of the host cache - effectively a host cache that doesn't contain any file contents, just metadata. (This way if the file is looked up for other reasons, that data is still there.) Finally, if both of those fail, we should hit disk (via the language server host).

Fixes #25047

Deleting the host cache was a performance optimization so we didn't hold on to file contents for files we weren't actively using - this should retain that invariant, since we're replacing the cache with one with no content.

@weswigham weswigham requested review from a user and sheetalkamat June 20, 2018 20:51
// hostCache is captured in the closure for 'getOrCreateSourceFile' but it should not be used past this point.
// It needs to be cleared to allow all collected snapshots to be released
hostCache = undefined!;
hostCache = hostCache.thinCopy(); // The thin copy does not cache any snapshots, just their paths, so is relatively safe to hold onto longer-term
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we should do this since in most cases we wont need it? (eg --declaration is not enabled this is not needed.. Its not needed if there is no need to create refactoring)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with removing it if we're fine with not having the cache available at that point; we can always come back and add it back if we discover perf is an issue here anyway.

@weswigham
Copy link
Member Author

@sheetalkamat I've removed it - we can always go add it later if we decide the perf is an issue.

}

function getOrCreateSourceFileByPath(fileName: string, path: Path, _languageVersion: ScriptTarget, _onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined {
Debug.assert(hostCache !== undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you do want to assert that hostCache !== undefined. That is getOrCreateSourceFileByPath should be called only when hostCache is not undefined.

@weswigham weswigham merged commit bd97e12 into microsoft:master Jun 22, 2018
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants